package cn.com.shopec.erp.product.commo;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.com.shopec.erp.base.entity.SupplierInfo;
import cn.com.shopec.erp.base.service.ISupplierInfoService;
import cn.com.shopec.erp.common.page.PageFinder;
import cn.com.shopec.erp.common.utils.LogicUtil;
import cn.com.shopec.erp.product.entity.ProdSupplier;
import cn.com.shopec.erp.product.vo.ProdSupplierVo;

@Component
public class ProdSupplierConvertor {
    @Resource
    private ISupplierInfoService supplierInfoService;

    public ProdSupplierVo getProdSupplierVo(ProdSupplier prodSupplier) {
        ProdSupplierVo prodSupplierVo = new ProdSupplierVo();
        if (LogicUtil.isNotNull(prodSupplier)) {
            prodSupplierVo.setSupplierNo(prodSupplier.getSupplierNo());
            prodSupplierVo.setProdNo(prodSupplier.getProdNo());
            prodSupplierVo.setUntaxCostPrice(prodSupplier.getUntaxCostPrice());
            prodSupplierVo.setTaxCostPrice(prodSupplier.getTaxCostPrice());
            prodSupplierVo.setGcrossMargin(prodSupplier.getGrossMargin());
            prodSupplierVo.setIsReturnedGoos(prodSupplier.getIsReturnedGoos());
            prodSupplierVo.setIsSupDelivery(prodSupplier.getIsSupDelivery());
            SupplierInfo supplierInfo = this.supplierInfoService
                    .getSupplierInfoBySuppCode(prodSupplier.getSupplierNo());
            prodSupplierVo.setSupplier(supplierInfo);
            if (LogicUtil.isNotNull(supplierInfo)) {
                prodSupplierVo.setSupplierName(supplierInfo.getSupName());
                prodSupplierVo.setAccount(supplierInfo.getAccount());
            }
        }

        return prodSupplierVo;
    }

    public PageFinder<ProdSupplierVo> getPageFinderProdSupplierVo(PageFinder<ProdSupplier> pageFinder) {
        List<ProdSupplierVo> prodSupplierVoList = this.getProdSupplierVoList(pageFinder.getData());

        PageFinder<ProdSupplierVo> pageFinderProdSupplierVo = new PageFinder<ProdSupplierVo>(pageFinder.getPageNo(),
                pageFinder.getPageSize(), pageFinder.getRowCount(), prodSupplierVoList);

        return pageFinderProdSupplierVo;

    }

    public List<ProdSupplierVo> getProdSupplierVoList(List<ProdSupplier> prodSupplierList) {
        List<ProdSupplierVo> prodSupplierVoList = new ArrayList<ProdSupplierVo>();
        if (LogicUtil.isNotNull(prodSupplierList)) {
            for (ProdSupplier prodSupplier : prodSupplierList) {
                ProdSupplierVo prodSupplierVo = new ProdSupplierVo();
                prodSupplierVo = this.getProdSupplierVo(prodSupplier);
                prodSupplierVoList.add(prodSupplierVo);
            }
        }
        return prodSupplierVoList;
    }
}
